#include <stdbool.h>
#include "bsp_timer.h"
#include "timer_config.h"
#include "stm32f4xx_hal.h"

#include "bsp_home_switch.h"
home_status_t home_status1, home_status2;
/**
  * @brief This function handles TIM6 global interrupt, DAC1 and DAC2 underrun error interrupts.
  * 5ms中断
  */
void TIM6_DAC_IRQHandler(void)
{
    HAL_TIM_IRQHandler(&htim6);
}

/**
  * @brief This function handles TIM4 global interrupt.
  * 1ms中断
  */
void TIM4_IRQHandler(void)
{
    HAL_TIM_IRQHandler(&htim4);
}

volatile uint64_t g_sys_time;

// volatile uint8_t g_is_callback_init = 0;
// void(*pf_rSdoTimeCount)(void);
// void(*pf_wSdoTimeCount)(void);
void(*pf_pvtMoveCtrl)(void);

/**
  * @brief  定时器中断回调函数
  * @note   This function is called  when TIMER interrupt took place, inside
  * HAL_TIM_IRQHandler(). 
  * @param  htim : TIM handle
  * @retval None
  */
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
    // 定时器4中断回调, 0.2ms
    if (htim == (&htim4))
    {
        g_sys_time++;

        // 零点开关硬件测试
        home_status1 = getHomeSwitchRawStatus(FIRST_SWITCH);
        home_status2 = getHomeSwitchRawStatus(SECOND_SWITCH);

        // if (g_is_callback_init)
        // {
        //   /*SDO写操作超时计时*/
        //   pf_wSdoTimeCount();

        //   /*SDO读操作超时计时*/
        //   pf_rSdoTimeCount();
        // }
    }

    // 定时器6中断回调, 5ms
    if (htim == (&htim6))
    {
        //TODO:
        // pf_pvtMoveCtrl();
    }
}

